package collection;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/**
 * 数组转集合
 */
public class ArrayToList {
    public static void main(String[] args) {
        String[] array = {"one","two","three","four","five"};
        System.out.println("array:"+ Arrays.toString(array));//array:[one, two, three, four, five]

        List<String> list = Arrays.asList(array);
        System.out.println("list:"+list);//list:[one, two, three, four, five]

        array[1] = "six";
        System.out.println("array:"+Arrays.toString(array));//array:[one, six, three, four, five]
        System.out.println("list:"+list);//array:[one, six, three, four, five]

        list.set(2,"seven");
        System.out.println("list:"+list);//list:[one, six, seven, four, five]
        System.out.println("array:"+Arrays.toString(array));//list:[one, six, seven, four, five]

        /*
           给集合添加/删除元素相当于给数组添加/删除元素
           而数组是定长的,不会自动扩容/缩容,因此发生不支持操作异常
           list.add("!!!");//运行时会发生不支持操作异常
         */

    }
}
